package com.agent.vpsserver.modules.admin.controller;

import com.agent.vpsserver.common.dto.AdminAccountTokenDTO;
import com.agent.vpsserver.common.dto.Result;
import com.agent.vpsserver.modules.admin.request.AdminUserIoginRequest;
import com.agent.vpsserver.modules.admin.response.AdminUserInfoResponse;
import com.agent.vpsserver.modules.admin.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 用户信息(AdminUser)表控制层
 *
 * @author guochao
 * @since 2022-11-01 19:08:37
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "运营后台 - 用户登录接口")
public class AdminUserController {
    /**
     * 服务对象
     */
    @Resource
    private AdminUserService adminUserService;

    @PostMapping(value = "/login")
    @ApiOperation(value = "登录")
    public Result<AdminUserInfoResponse> login(@RequestBody @Valid AdminUserIoginRequest request) {
        return Result.success(adminUserService.login(request));
    }

    @PostMapping(value = "/logout")
    @ApiOperation(value = "退出登录")
    public Result logout(@RequestBody @Valid AdminAccountTokenDTO request) {
        adminUserService.logout(request);
        return Result.success();
    }
}
